#include <iostream>
#include <algorithm> 
using namespace std;
struct node 
{
	int s,e;
	int flag;
} ;

node src[210];

int cmp(const node & a,const node & b)
{
	if(a.s==b.s){
		return a.e<b.e;
	}
	else return a.s<b.s;
}


int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<n;i++) {
			cin>>src[i].s>>src[i].e;
			if(src[i].s>src[i].e){
				int temp=src[i].s;
				src[i].s=src[i].e;
				src[i].e=temp;
			}
			src[i].flag=0;
		}
		sort(src,src+n,cmp);
		int ans=0;
		for(int i=0;i<n;i++){
			if(src[i].flag==0){
				ans++;
				src[i].flag=1;
				int index=i;
				for(int j=i+1;j<n;j++){
					if(src[j].s>=src[index].e&&src[j].flag==0&&!(src[j].s%2==0&&(src[j].s-1==src[index].e))){
						index=j;
						src[j].flag=1;
					}
				}
			}
		}
		cout<<ans*10<<endl;
	}
}
